package com.xiaolei.lib.annotation.translators;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import com.xiaolei.lib.Activity.IActivity;
import com.xiaolei.lib.Activity.bean.AnnotationWrape;
import com.xiaolei.lib.annotation.getBoolean;
import com.xiaolei.lib.annotation.getSharedPreferences;
import com.xiaolei.lib.core.ITranslator;

import android.content.SharedPreferences;


public class getSharedPreferences_getBoolean_Translator implements ITranslator
{

	@Override
	public void execute(Field field, IActivity activity, AnnotationWrape annotation)
	{
		getSharedPreferences gPreferences = annotation.get(getSharedPreferences.class);
		getBoolean gBoolean = annotation.get(getBoolean.class);
		String name = gPreferences.value();
		int mode = gPreferences.mode();
		SharedPreferences sharedPreferences = activity.getSharedPreferences(name, mode);
		String bName = gBoolean.value();
		boolean defaultVaule = gBoolean.defaultValue();
		boolean result = sharedPreferences.getBoolean(bName, defaultVaule);
		try
		{
			if (!field.isAccessible())
			{
				field.setAccessible(true);
			}
			field.set(activity, result);
		} catch (Exception e)
		{
		}
		
	}

	@Override
	public void execute(Method method, IActivity activity, AnnotationWrape annotation)
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public void execute(Class<?> type, IActivity activity, AnnotationWrape annotation)
	{
		// TODO Auto-generated method stub
		
	}
	
}
